package com.kevis.zhunblog.core.entities;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 博客文章
 *
 * @TableName t_article
 */
@TableName(value = "t_article")
@Data
public class ArticleEntity implements Serializable {
    /**
     * 主键自增
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @TableField(value = "create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @TableField(value = "update_time")
    private LocalDateTime updateTime;

    /**
     * 状态
     */
    @TableField(value = "status")
    private Byte status;

    /**
     * 文章标题
     */
    @TableField(value = "title")
    @NotBlank(message = "标记名称不能为空")
    @Size(max = 50,message = "标记名称长度不能超过50个字符")
    private String title;

    /**
     * 博客简介
     */
    @TableField(value = "summary")
    @Size(max = 50,message = "标记名称长度不能超过50个字符")
    private String summary;

    /**
     * 博客内容
     */
    @TableField(value = "content")
    private String content;

    /**
     * 博客分类id
     */
    @TableField(value = "class_id")
    private Integer classId;

    /**
     * 点击数
     */
    @TableField(value = "num_click")
    private Integer numClick;

    /**
     * 点赞数
     */
    @TableField(value = "num_favorite")
    private Integer numFavorite;

    /**
     * 封面图的id
     */
    @TableField(value = "thumbnail_file_id")
    private Integer thumbnailFileId;

    /**
     * 排序，默认6666
     */
    @TableField(value = "sort")
    private Integer sort;

    /**
     * 是否开启评论(0:否 1:是)
     */
    @TableField(value = "open_comment")
    private Byte openComment;

    /**
     * 作者
     */
    @TableField(value = "author")
    private String author;

    /**
     * 文章出处
     */
    @TableField(value = "articles_part")
    private String articlesPart;

    /**
     * 管理员id
     */
    @TableField(value = "admin_id")
    private Integer adminId;

//    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//    @JsonSerialize(using = LocalDateTimeSerializer.class)
//    @JsonFormat(shape=JsonFormat.Shape.STRING,locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(value = "release_time")
    private Timestamp releaseTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}